package com.cheetah.listener;

import com.cheetah.client.CheetahClient;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoop;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Author Administrator
 * @Date 2019/8/1
 * @Version V1.0
 * @Description:
 **/
@Component
@Slf4j
public class ConnectListner implements ChannelFutureListener {

    private CheetahClient client;

    public ConnectListner(CheetahClient client){
        this.client = client;
    }

    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
//        if (!future.isSuccess()) {
//            final EventLoop loop = future.channel().eventLoop();
//            loop.schedule(new Runnable() {
//                @Override
//                public void run() {
//                    System.err.println("服务端链接不上，开始重连操作...");
//                    client.createClient();
//                }
//            }, 1L, TimeUnit.SECONDS);
//        } else {
//
//            System.err.println("服务端链接成功...");
//        }

        if (!future.isSuccess()) {
            future.channel().pipeline().fireChannelInactive();
        }
    }
}
